package com.basksoft.baskreport.demo.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.basksoft.report.core.database.model.Page;
import com.basksoft.report.core.database.model.User;
import com.basksoft.report.core.database.serivce.user.UserService;

public class TestUserService implements UserService {

	@Override
	public void getUsers(Page<User> page, Map<String, Object> parameters) {
		List<User> users = new ArrayList<User>();
		page.setTotalRows(10);
		users.add(get("admin"));
		users.add(get("anlin"));
		page.setData(users);
	}

	@Override
	public User get(String account) {
		User user = new User();
		user.setAccount(account);
		user.setAdmin("admin".equals(account));
		user.setCreateDate(new Date());
		user.setCreateUser("admin");
		user.setEnable(true);
		user.setPassword("admin");
		user.setUsername("admin".equals(account)?"管理员":"用户"+account);
		
		return user;
	}

	@Override
	public User validate(String account, String password) {
		if ("admin".equals(account)) {
			return get(account);
		} else {
			User user = get(account);
			user.setAdmin(false);
			user.setUsername("用户"+account);
			return user;
		}
	}

}
